﻿using System.IO;
using System.IO.Compression;
using System.Web;

namespace Nana.Web.Compressing
{
  public sealed class GZipFilterFactory
    : ResponseFilterFactory
  {
    private GZipFilterFactory() { }

    [FactoryInstance]
    public static GZipFilterFactory Instance { get; private set; }

    static GZipFilterFactory()
    {
      Instance = new GZipFilterFactory();
    }

    public override void SetupHeaders(HttpContext context)
    {
      context.Response.AppendHeader("Content-Encoding", "gzip");
    }

    public override Stream CreateFilter(Stream baseFilter)
    {
      return new GZipStream(baseFilter, CompressionMode.Compress);
    }
  }
}
